package org.example.springrocketmq.myrocketmq.Producer;


import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

@Component
public class SpringProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    public void sendMessage() throws UnsupportedEncodingException {
        for (int i = 0; i < 10; i++) {
            //发送消息
            Message message = new Message("TopicTest","TagA","orderId188",("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
            rocketMQTemplate.syncSend("TopicTest",message);
            rocketMQTemplate.syncSendOrderly("TopicTest",message,String.valueOf(i));
//            rocketMQTemplate.syncSend("TopicTest","message",1000,2);

}
    }
}

